package com.android.alertdialogedittest;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Button;
import android.app.AlertDialog;
import android.content.DialogInterface;


public class AlertDialogEditTest extends Activity
{

    private Button button;
    private TextView view;
    private EditText edit;


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


        button = (Button) findViewById (R.id.Button01);
        view = (TextView) findViewById (R.id.TextView01);

        final AlertDialog.Builder builder = new AlertDialog.Builder (this)
        .setTitle ("Leave some words.")
        .setMessage ("Thank you for your words.")
        .setIcon (R.drawable.icon)
        .setPositiveButton ("OK", new DialogInterface.OnClickListener (){

            public void onClick (DialogInterface dialog, int whichButton){
                setResult (RESULT_OK);
                    //finish ();
                view.setText(edit.getText().toString());
            }


        });


        button.setOnClickListener (new Button.OnClickListener () {
            public void onClick (View v){
                edit = new EditText (AlertDialogEditTest.this);
                builder.setView (edit);
                builder.show ();
            }
        });

    }
}
